package com.hzyl.famousreader.view.adapter;

import android.support.annotation.Nullable;
import android.widget.ImageView;
import com.blankj.utilcode.util.StringUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hzyl.famousreader.R;
import com.hzyl.famousreader.repository.persistence.entity.Ad;

import java.util.List;

/**
 * 广告适配器
 */
public class AdAdapter extends BaseQuickAdapter<Ad, BaseViewHolder> {

  public AdAdapter(@Nullable List<Ad> data) {
    super(R.layout.item_ad, data);
  }

  @Override
  protected void convert(BaseViewHolder helper, Ad item) {
    Glide.with(mContext).load(item.getPath()).into((ImageView) helper.getView(R.id.discovery_iv_ad_img));

    if (StringUtils.isEmpty(item.getTitle())) {
      helper.setGone(R.id.discovery_tv_title, false);
    } else {
      helper.setText(R.id.discovery_tv_title, item.getTitle());
    }

    if (StringUtils.isEmpty(item.getDescription())) {
      helper.setGone(R.id.discovery_tv_description, false);
    } else {
      helper.setText(R.id.discovery_tv_description, item.getDescription());
    }
  }
}
